/*******************************************************************************
 * Copyright 2011 @ Kapil Viren Ahuja
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.kapil.framework.test.core;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.annotations.BeforeSuite;

import com.kapil.framework.database.IDatabaseSetup;
import com.kapil.framework.exception.BaseException;
import com.kapil.framework.logger.ILogger;
import com.kapil.framework.logger.LogFactory;

/**
 * <p>
 * Base class for all other test cases in the application. This class provides the following functionalities:
 * <ol>
 * <li>Loads Spring's base context</li>
 * <li>Loads all the data in to the Database</li>
 * <li>Method to loads beans from Spring Context</li>
 * </ol>
 * </p>
 */

public abstract class BaseTestCase
{
    private static final ILogger LOGGER = LogFactory.getInstance().getLogger(BaseTestCase.class);

    protected static final ClassPathXmlApplicationContext context;

    static
    {
        context = new ClassPathXmlApplicationContext("rootTestContext.xml");
        context.registerShutdownHook();
        
        BaseException.addDataSource("FrameworkTestMessages");
    }
    
    
    @BeforeSuite
    public void beforeSetup()
    {
        LOGGER.info("Starting Test Suite");
    }

    
    protected Object getBean(String name)
    {
        return context.getBean(name);
    }


    protected IDatabaseSetup getDatabaseSetupBean()
    {
       return (IDatabaseSetup) this.getBean("baseDatabaseSetup");
    }
}
